package com.frxuexi.lib_base.http

import android.content.Context
import androidx.room.Room
import com.frxuexi.lib_base.room.LoginDao
import com.frxuexi.lib_base.room.OrderDao
import com.frxuexi.lib_base.room.ParkDataBase
import com.frxuexi.lib_base.room.ShopDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ProvideFactory {


    @Provides
    @Singleton
    fun getApiService():ApiService=RetrofitUtil.retrofit.create(ApiService::class.java)


    @Provides
    @Singleton
    fun getShopApiService():ShopApiService=RetrofitUtil.retrofitShop.create(ShopApiService::class.java)

    @Provides
    @Singleton
    fun initDB(@ApplicationContext context: Context):ParkDataBase{
        return Room.databaseBuilder(context,ParkDataBase::class.java,"park2304.db")
            .allowMainThreadQueries()
            .build()
    }

    @Provides
    @Singleton
    fun getLoginDao(dataBase: ParkDataBase):LoginDao=dataBase.loginDao()

    @Provides
    @Singleton
    fun getShopDao(dataBase: ParkDataBase):ShopDao=dataBase.shopDao()

    @Provides
    @Singleton
    fun getOrderDao(dataBase: ParkDataBase):OrderDao=dataBase.orderDao()
}